package com.example.yuanqin.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

class SplashViewModel:ViewModel() {


    private val _downTime:MutableLiveData<Int> = MutableLiveData<Int>()
    val downTime:LiveData<Int> = _downTime

    fun initDownTIme(){
        _downTime.value = 5
    }

    fun timeDown(){
        if (_downTime.value!=null){
            _downTime.value = _downTime.value!! -1
        }
    }
}

class SplashViewModelFactory:ViewModelProvider.Factory{
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(SplashViewModel::class.java)){
            return SplashViewModel() as T
        }
        throw IllegalAccessException("Unknown ViewModel class")
    }

}